"""add ai analysis results table

Revision ID: 64208e9a5205
Revises: 6a055e5b07ed
Create Date: 2024-03-21 10:00:00.000000

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = '64208e9a5205'
down_revision: Union[str, None] = '6a055e5b07ed'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    """Upgrade schema."""
    # 创建AI分析结果表
    op.create_table(
        'ai_analysis_results',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('task_id', sa.Integer(), nullable=False),
        sa.Column('file_path', sa.String(length=255), nullable=False),
        sa.Column('function_name', sa.String(length=255), nullable=False),
        sa.Column('start_line', sa.Integer(), nullable=False),
        sa.Column('end_line', sa.Integer(), nullable=False),
        sa.Column('analysis_content', sa.Text(), nullable=False),
        sa.Column('created_at', sa.DateTime(), nullable=False),
        sa.ForeignKeyConstraint(['task_id'], ['scan_tasks.id'], ),
        sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_ai_analysis_results_id'), 'ai_analysis_results', ['id'], unique=False)


def downgrade() -> None:
    """Downgrade schema."""
    # 删除AI分析结果表
    op.drop_index(op.f('ix_ai_analysis_results_id'), table_name='ai_analysis_results')
    op.drop_table('ai_analysis_results')
